package cn.itcast.bos.domain.auth;

// Generated 2016-5-4 16:20:01 by Hibernate Tools 3.2.2.GA

import java.math.BigDecimal;
import java.util.HashSet;
import java.util.Set;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Transient;
import javax.persistence.UniqueConstraint;

import org.hibernate.annotations.GenericGenerator;

/**
 * Function generated by hbm2java
 */
@Entity
@Table(name = "AUTH_FUNCTION", schema = "ITCAST27", uniqueConstraints = @UniqueConstraint(columnNames = "NAME"))
public class Function implements java.io.Serializable {

	private String id;
	private Function function;
	private String name;
	private String code;
	private String description;
	private String page;
	private String generatemenu;
	private BigDecimal zindex;
	private Set<Role> roles = new HashSet<Role>(0);
	private Set<Function> functions = new HashSet<Function>(0);

	@Transient
	// 测试之后 不行... javabean getPid(不行) getpId 采用这种
	public String getpId() {
		if (function == null) {
			return "0";
		} else {
			return function.getId();
		}
	}

	public Function() {
	}

	public Function(Function function, String name, String code, String description, String page, String generatemenu, BigDecimal zindex, Set<Role> roles, Set<Function> functions) {
		this.function = function;
		this.name = name;
		this.code = code;
		this.description = description;
		this.page = page;
		this.generatemenu = generatemenu;
		this.zindex = zindex;
		this.roles = roles;
		this.functions = functions;
	}

	@GenericGenerator(name = "generator", strategy = "uuid")
	@Id
	@GeneratedValue(generator = "generator")
	@Column(name = "ID", unique = true, nullable = false, length = 32)
	public String getId() {
		return this.id;
	}

	public void setId(String id) {
		this.id = id;
	}

	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "PID")
	public Function getFunction() {
		return this.function;
	}

	public void setFunction(Function function) {
		this.function = function;
	}

	@Column(name = "NAME", unique = true)
	public String getName() {
		return this.name;
	}

	public void setName(String name) {
		this.name = name;
	}

	@Column(name = "CODE")
	public String getCode() {
		return this.code;
	}

	public void setCode(String code) {
		this.code = code;
	}

	@Column(name = "DESCRIPTION")
	public String getDescription() {
		return this.description;
	}

	public void setDescription(String description) {
		this.description = description;
	}

	@Column(name = "PAGE")
	public String getPage() {
		return this.page;
	}

	public void setPage(String page) {
		this.page = page;
	}

	@Column(name = "GENERATEMENU")
	public String getGeneratemenu() {
		return this.generatemenu;
	}

	public void setGeneratemenu(String generatemenu) {
		this.generatemenu = generatemenu;
	}

	@Column(name = "ZINDEX", precision = 22, scale = 0)
	public BigDecimal getZindex() {
		return this.zindex;
	}

	public void setZindex(BigDecimal zindex) {
		this.zindex = zindex;
	}

	@ManyToMany(fetch = FetchType.LAZY)
	@JoinTable(name = "ROLE_FUNCTION", schema = "ITCAST27", joinColumns = { @JoinColumn(name = "FUNCTION_ID", nullable = false, updatable = false) }, inverseJoinColumns = { @JoinColumn(name = "ROLE_ID", nullable = false, updatable = false) })
	public Set<Role> getRoles() {
		return this.roles;
	}

	public void setRoles(Set<Role> roles) {
		this.roles = roles;
	}

	@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY, mappedBy = "function")
	public Set<Function> getFunctions() {
		return this.functions;
	}

	public void setFunctions(Set<Function> functions) {
		this.functions = functions;
	}

}
